const Router = require('koa-router')

const { login, updatePwd, create, update, query, updateOnDuty, resetPwd } = require('../controller/employee.controller')
const { auth, verifyAdmin } = require('../middleware/auth.middleware')
const { validatort } = require('../middleware/validator.middlewear')
const { formatError } = require('../constant/error.type')

const router = new Router({ prefix: '/employee' })

router.post('/login', validatort({ phone: 'string', password: 'string' }, formatError), login)

router.put('/updatePassword', auth, validatort({ password: 'string' }), updatePwd)

router.post('/', auth, verifyAdmin, validatort({ phone: 'string', empName: 'string' }, formatError), create)

router.put('/', auth, validatort({ phone: 'string', empName: 'string' }, formatError), update)

router.get('/', auth, query)

router.put('/onDuty/:id', auth, verifyAdmin, updateOnDuty)

router.post('/resetPwd', auth, verifyAdmin, validatort({ id: 'array' }, formatError), resetPwd)

module.exports = router

